﻿<Window x:Class="SqlServerRunnerNet.ServerBrowserWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		xmlns:viewModel="clr-namespace:SqlServerRunnerNet.ViewModel"
		xmlns:utils="clr-namespace:SqlServerRunnerNet.Utils"
		mc:Ignorable="d" Title="Servers" Height="400" Width="350" ShowInTaskbar="False"
		d:DataContext="{d:DesignInstance viewModel:ServerBrowserWindowViewModel}">
	<Window.Resources>
		<CollectionViewSource x:Key="LocalInstancesCollection" Source="{Binding LocalInstancesCollection}" />
		<CollectionViewSource x:Key="RemoteInstancesCollection" Source="{Binding RemoteInstancesCollection}" />
	</Window.Resources>
	<Grid Margin="5">
		<Grid.RowDefinitions>
			<RowDefinition Height="*" />
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>
		<ListBox x:Name="ListBox" Grid.Row="0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto">
			<ListBox.ItemsSource>
				<CompositeCollection>
					<CollectionContainer Collection="{Binding Source={StaticResource LocalInstancesCollection}}" />
					<CollectionContainer Collection="{Binding Source={StaticResource RemoteInstancesCollection}}" />
					<ListBoxItem IsHitTestVisible="False">
						<ListBoxItem.Style>
							<Style TargetType="ListBoxItem">
								<Setter Property="Visibility" Value="Collapsed" />
								<Style.Triggers>
									<DataTrigger Binding="{Binding IsLoading}" Value="True">
										<Setter Property="Visibility" Value="Visible" />
									</DataTrigger>
								</Style.Triggers>
							</Style>
						</ListBoxItem.Style>
						<TextBlock FontStyle="Italic">Loading items...</TextBlock>
					</ListBoxItem>
				</CompositeCollection>
			</ListBox.ItemsSource>
			<ListBox.ItemTemplate>
				<DataTemplate DataType="utils:SqlServerInstance">
					<StackPanel Orientation="Horizontal" Margin="2">
						<Image x:Name="SqlServerInstanceImage" Source="/SqlServerRunnerNet;component/Images/web.png" Margin="0,0,5,0" />
						<TextBlock Text="{Binding}"/>
					</StackPanel>
					<DataTemplate.Triggers>
						<DataTrigger Binding="{Binding IsLocal}" Value="True">
							<Setter TargetName="SqlServerInstanceImage" Property="Source" Value="/SqlServerRunnerNet;component/Images/home.png" />
						</DataTrigger>
					</DataTemplate.Triggers>
				</DataTemplate>
			</ListBox.ItemTemplate>
		</ListBox>
		<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,5,0,0" HorizontalAlignment="Center">
			<Button IsDefault="True" Click="OkButton_OnClick" Padding="15,3" IsEnabled="{Binding SelectedItems.Count, ElementName=ListBox, Mode=OneWay}">OK</Button>
			<Button IsCancel="True" Padding="15,3">Cancel</Button>
		</StackPanel>
	</Grid>
</Window>
